package ace.game;

import java.io.IOException;

import javax.microedition.lcdui.Image;

import ace.system.Utilities;

public class Tileset {
	public Tileset(String image) {
        //Create with default column
		this(image, Utilities.TILESET_COLUMN);
	}

	public Tileset(String image, int column) {
		//Create tiles
		try {
			//Create image
			Image Source 	= Image.createImage(image);
			m_Images		= new Image[column * (Source.getHeight() / Utilities.TILE_HEIGHT)];
			
			//Slice it
			for (int y = 0; y < Source.getHeight() / Utilities.TILE_HEIGHT; y ++) {
				for (int x = 0; x < column; x++) {
					m_Images[(y * column) + x] = Image.createImage(
							Source,
							x * Utilities.TILE_WIDTH,
							y * Utilities.TILE_HEIGHT,
							Utilities.TILE_WIDTH,
							Utilities.TILE_HEIGHT, 0);
				}
			}
		} catch (IOException e) {}
	}
	
	public Image getTile(int index) {
		return m_Images[index];
	}
	
	protected Image[]   m_Images;
}
